/***************************************************************
Made by: Cultured::Labs

Copyright (c) 2010 Cultured::Labs
****************************************************************/
#include <fstream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include "getWord.h"
using namespace std;

string getWord() {
  //opens file for reading
  ifstream input_file ("word_list.txt");
  if (!input_file.is_open()) {
    string error = "#error#";
    return error;
  }

  //determines the number of words
  int WORDCOUNT;
  stringstream to_int;
  string temp;
  getline(input_file, temp);
  to_int << temp;
  to_int >> WORDCOUNT;

  //gets a random index
  int index;
  srand((unsigned)time(NULL));
  index = (rand() % WORDCOUNT) + 1;

  //reads the word
  string word;
  if (input_file.is_open()) {
    for (int i = 1; i <= index; i++) {
      getline(input_file, word);
    }
    input_file.close();
  }

  return word;
}
